<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
</head>

<body>
    <h2>登录页面</h2>
    <form action="/user/login" method="post">
        <span>用户名：</span>
        <input type="text" placeholder="用户名" name="name">
        </br>
        <span>密&nbsp&nbsp&nbsp码：</span>
        <input type="password" placeholder="密码" name="psd">
        <!-- </br>
        <span>性别：</span>
        <span>男 </span>
        <input type="radio" name="sex" value="1">
        <span>女 </span>
        <input type="radio" name="sex" value="2"> -->
        </br>
        <input type="submit" value="登录">
    </form>
    <script>
        const form = document.getElementById('form')
        form.addEventListener('submit', async (e) => {
            e.preventDefault()
            const data = new FormData(form)
            const params = {}
            for (const iterator of data.keys()) {
                params[iterator] = data.get(iterator)
            }
            const result = await fetch('http:127.0.0.1:8080/user/login', {
                method: 'post',
                body: JSON.stringify(params),
                headers: {
                    'content-type': 'application/json'
                }
            })
            const res = await result.json()
            console.log(res)
            if (res.data) {
                if (confirm(res.msg)) {
                    // window.location.href = 'http://127.0.0.1:8080/user/loginpage'
                }

            } else {
                alert(res.msg)
            }
        })

    </script>
</body>

</html>